/*****  Component, by Ben Bi <prince.bi@gmail.com>  created at: 12/23/2009 4:10:45 PM  *****/

/********   Notes:  *******
 *
 *  
 */
$(document).ready(
    function() {
        $("#floatingPanel").draggable({ handle: 'div.wacPortlet-header' });
        $("#stock_goods_inquiry_factory_id").attr("selectedIndex", 0);

        initStockGoodsInquiryList();
        
        bindStockGoodsInquiryEvents();
    }
);

function bindStockGoodsInquiryEvents(){
    $("#stock_goods_inquiry_factory_id").bind("change", function(e){
        var params = {dataFormat :"json",
                      searchOper :"eq",
                      searchField : "factory_id",
                      searchString : $(e.currentTarget).val()
                     };
//        $("#" + moduleListId).jqGrid('setGridParam',{url: BASE_URL+"test/ajaxTest"})
        $("#stock_goods_inquiry_list").jqGrid('setGridParam',{datatype:"json"});
        $("#stock_goods_inquiry_list").jqGrid('setGridParam',{postData:params});
        $("#stock_goods_inquiry_list").trigger("reloadGrid");
    })

}

function initStockGoodsInquiryList(){
    jQuery("#stock_goods_inquiry_list").jqGrid({
        datatype: "local",
        url: BASE_URL+"factoryGoodsItem/getList",
        editurl: "",
        postData: {dataFormat: "json"},
        colNames:['id', '货物', '数量', '货物单位',
            '操作' ],
        colModel:[
            {name:"id", index:"id", editable:false, hidden:true, width:30},
            {name:'goods_name', index:'goods_name', editable:false, width:135, align:"left"},
            {name:'goods_number', index:'goods_number', editable:false, width:80, align:"left"},
            {name:'goods_number_unit_code_name', index:'goods_number_unit_code_name', editable:false, width:80, align:"left"},
            {name:'act', index:'act', width:120, editable:false, sortable:false, align:"center", hidden:true}
        ],
        jsonReader : {
            root:"items",
            page: "currentPage",
            total: "totalPages",
            records: "totalRecords",
            userdata: "userdata",
            id: "id",
            repeatitems: false
        },
        rowNum:10,
        rowList:[10,20,30,40,50],
        pager: '#stock_goods_inquiry_pager',
        height: '100%',
        sortname: 'goods_name',
        sortorder: "asc",
        multiselect: false,
        subGrid: false
        }); // grid end

        jQuery("#stock_goods_inquiry_list").jqGrid('navGrid','#stock_goods_inquiry_pager',
        {edit:false, add:false, del:false, search:true, refresh:true, view:false, position:"left"});
}

/**************  interaction section, end  ***************/